<?php

/*
 * Copyright 2014 T J Morgan.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 * House Ledger - a web application with the intention of being useful to
 * semi-automatic track bills and payments between members of a shared house hold.
 * 
 * Author: Tim Morgan
 */

/*
 * File Description
 * 
 * Class to manage the House Balance,
 * and manage transactions operations between multiple accounts
 */

namespace Ledger\Model\Bank;

abstract class Bank {
    public static function pay(Account $from, Account $to, $amount = null, Bill $bill = null, $communal = true, $reimbursals = null) {
        // check we know how much to pay
        if($amount === null){
            if($bill !== null)
                $amount = $bill->amount;
            else
                throw new \BadMethodCallException("No amount or bill specified for payment");
        }
        
        if ($amount == 0)
            throw new ErrorException("Cannot pay zero; there is nothing to deposit!");
        else if ($amount == 0)
            throw new ErrorException("Cannot deposit a negative amount!");
        
        try{
            // create transaction from params.. record in db, then refresh state and return ?
            // Really no need for withdraw, deposit, etc. - the systems is the only thing controlling the funds?
            
        } catch (Exception $ex) {

        }
    }

}
